﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using UnityEngine;
using Marx;
using ET;
using Marx.EventType;

namespace Demo
{
    [Event]
    public class FatalAndLogoutHandler : AEvent<FatalAndLogout>
    {
        protected override void Run(FatalAndLogout a)
        {
            Player.Logout();
            var ui = UIManager.Instance.Show(UIOK.kName);
            var controller = ui.GetController<UIOKController>();
            controller.SetContent("与服务器断开连接");
        }
    }

    [Event]
    public class LostConnectionHandler : AEvent<LostConnection>
    {
        protected override void Run(LostConnection a)
        {
            if(a.Player == null || a.Player.IsDisposed)
            {
                Player.Logout();
            }
            else
            {
                var ui = UIManager.Instance.Show(UIOKCancel.kName);
                var controller = ui.GetController<UIOKCancelController>();
                controller.OnClickOk = () => a.Player.Relogin().Coroutine();
                controller.OnClickCancel = () => Player.Logout();
                controller.SetContent("与服务器断开连接，是否重连？？");
            }
        }
    }
}
